//microcommand define -lnnbot-react
ctx = ctx.platform("onebot").guild()
signature("<emojis:el>", { captureQuote: false })
option("remove", "-r", { notUsage: true })
action(async ({ session, options }, els) => {
  const message_id = session.event.message?.quote?.id ?? session.messageId
  let flag = false
  async function f(els) {
    for (const el of els) {
      if (el.type === "text") {
        const mm = el.attrs.content.match(/\p{S}/gu)
        if (mm) {
          flag = true
          for (const m of mm) {
            await session.onebot._get("set_msg_emoji_like", { message_id, emoji_id: m.codePointAt(0) })
          }
        }
      } else if (el.type === "face" && (!el.attrs.platform || el.attrs.platform === "onebot")) {
        flag = true
        await session.onebot._get("set_msg_emoji_like", { message_id, emoji_id: el.attrs.id, set: !options.remove })
      } else {
        await f(el.children)
      }
    }
  }
  await f(els)
  if (!flag) return session.text(".invalid")
})

locale("zh-CN", {
  description: "给消息添加表情回应",
  messages: {
    invalid: "缺少要贴的表情…"
  }
})